package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.TAppBalanceMapper;
import com.ruoyi.system.domain.TAppBalance;
import com.ruoyi.system.service.ITAppBalanceService;

/**
 * 余额Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-04-23
 */
@Service
public class TAppBalanceServiceImpl implements ITAppBalanceService 
{
    @Autowired
    private TAppBalanceMapper tAppBalanceMapper;

    /**
     * 查询余额
     * 
     * @param id 余额主键
     * @return 余额
     */
    @Override
    public TAppBalance selectTAppBalanceById(Long id)
    {
        return tAppBalanceMapper.selectTAppBalanceById(id);
    }

    /**
     * 查询余额列表
     * 
     * @param tAppBalance 余额
     * @return 余额
     */
    @Override
    public List<TAppBalance> selectTAppBalanceList(TAppBalance tAppBalance)
    {
        return tAppBalanceMapper.selectTAppBalanceList(tAppBalance);
    }

    /**
     * 新增余额
     * 
     * @param tAppBalance 余额
     * @return 结果
     */
    @Override
    public int insertTAppBalance(TAppBalance tAppBalance)
    {
        tAppBalance.setCreateTime(DateUtils.getNowDate());
        return tAppBalanceMapper.insertTAppBalance(tAppBalance);
    }

    /**
     * 修改余额
     * 
     * @param tAppBalance 余额
     * @return 结果
     */
    @Override
    public int updateTAppBalance(TAppBalance tAppBalance)
    {
        return tAppBalanceMapper.updateTAppBalance(tAppBalance);
    }

    /**
     * 批量删除余额
     * 
     * @param ids 需要删除的余额主键
     * @return 结果
     */
    @Override
    public int deleteTAppBalanceByIds(Long[] ids)
    {
        return tAppBalanceMapper.deleteTAppBalanceByIds(ids);
    }

    /**
     * 删除余额信息
     * 
     * @param id 余额主键
     * @return 结果
     */
    @Override
    public int deleteTAppBalanceById(Long id)
    {
        return tAppBalanceMapper.deleteTAppBalanceById(id);
    }

    @Override
    public int importTAppBalances(List<TAppBalance> tAppBalances) {
        if (StringUtils.isNull(tAppBalances) || tAppBalances.size() == 0) {
            throw new ServiceException("导入账户数据不能为空！");
        }
        for (TAppBalance tAppBalance : tAppBalances) {
            tAppBalance.setUpdateTime(DateUtils.getNowDate());
            tAppBalance.setUserId(1001l);
            tAppBalanceMapper.insertTAppBalance(tAppBalance);
        }
        return tAppBalances.size();
    }
}
